#include <stdlib.h>
#include <string.h>
#include "xhash.h"
#include "xstr.h"

struct xstr* string(char *str){
  int len=strlen(str);

  int struct_size=sizeof(struct xstr);
  void *p=  malloc(struct_size);
  struct xstr* pstr=(struct xstr*)p;

  char *dest=(char *)malloc(struct_size+1);
  pstr->len=len;
  char *ret=strcpy(dest,str);
  dest[struct_size]='\0';
  pstr->str=dest;
  pstr->hash=0;
  return pstr;
}

int xstrHashCode(struct xstr *xstr){

  int hashCode=  xstr->hash;
  if(hashCode){
    return hashCode;
  }
  hashCode= xhash4str(xstr->str);
  xstr->hash=hashCode;
  return hashCode;
}

